package com.hgh.javase6_4;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.Timer;

public class TalkingClock {

	public TalkingClock(int interval, boolean beep) {
		this.beep = beep;
		this.interval = interval;
	}

	public void start() {
		// ActionListener listener = new TimePrinter();
		ActionListener listener = this.new TimePrinter();
		Timer timer = new Timer(interval, listener);
		timer.start();
	}

	private int interval;
	private boolean beep;

	public class TimePrinter implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			Date now = new Date();
			System.out.println("at the tone, the time is" + now);
			// if (beep) {
			if (TalkingClock.this.beep) {
				Toolkit.getDefaultToolkit().beep();
			}
		}

	}
}
